#include <benchmark/benchmark.h>
#include "sys/types.h"
#include "sys/socket.h"
#include "netdb.h"
#include "util.h"

using namespace std;

static void Bm_function_Getaddrinfo(benchmark::State &state)
{
    struct addrinfo hints;
    struct addrinfo *res;
    bzero(&hints, sizeof(struct addrinfo));
    hints.ai_flags = AI_CANONNAME;
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    for (auto _ : state)
    {
        int n = getaddrinfo(nullptr, "8081", &hints, &res);
        if (n != 0)
        {
            perror("getaddrinfo");
            exit(EXIT_FAILURE);
        }
        benchmark::DoNotOptimize(n);
    }
    state.SetItemsProcessed(state.iterations());
}

MUSL_BENCHMARK(Bm_function_Getaddrinfo);